<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>file/shell/smooth/resources/css/jquery.dataTables.css" />

<base href="<?php echo base_url(); ?>">
<table id="dataList" width="100%" class="dataTable">
  <thead>
    <tr>
      <!-- <th width="20px">#</th> -->
      <th width="80px">Scan ID</th>
      <th width="100px">Tanggal Scan</th>
      <th width="80px">Sales ID</th>
      <th>Sales Name</th>
      <th>Akses Dari</th>
      <!-- <th>Detail</th> -->
    </tr>
  </thead>
  
  <tbody><!-- Here goes the datatables --></tbody>

</table>

<script type="text/javascript">
$(document).ready(function() {

  $('#dataList').dataTable({
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "<?php echo base_url('index.php/scan/dataList');?>/",
    "aoColumnDefs": [
      { "bSearchable": false, "aTargets": [0,1] }
    ],
    "fnRowCallback": function(nRow, aaData, iDisplayIndex, iDisplayIndexFull) 
    {
      // $(nRow).find('td').eq(0).before('<td>'+(parseInt(iDisplayIndex,10)+1+parseInt(dis))+'</td>');

      $.post(
        "<?=base_url();?>index.php/outlet/fogit/",
        {outlet_id:aaData[0]},
        function(response) {
            // $('#active-outlet tbody tr').eq(iDisplayIndex).find('a').eq(i).attr('href', new_href_active);
            $(nRow).find('td').eq(-1).after('<td><a href="index.php/scan/detail/'+response+'">Detail</a> | <a href="index.php/scan_history/topdf/'+response+'">PDF</a></td>'); 
          }
      );
      // $(nRow).find('td').eq(-1).after('<a href="index.php/sell/getDetail/'+aaData[0]+'">actison</a>'); //buat link action 

        return nRow;
    },
    "fnServerData": function ( sSource, aoData, fnCallback ) { 
        $.getJSON( sSource, aoData, function (json) { 
                    
        dis=json['iDisplayStart'];
        fnCallback(json);
    });} ,

    // 'fnDrawCallback': function ( oSettings, nRow, aaData ) {
      // if ( oSettings.bSorted || oSettings.bFiltered )
      // {
        // for ( var i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ )
        // { $('td:eq(0)', oSettings.aoData[ oSettings.aiDisplay[i] ].nTr ).before( i+1 ); }
      // } 
    // }

  });
  // $('#dataList thead tr').find('th').eq(0).before('<th class="sorting_disabled" role="columnheader" rowspan="1" colspan="1" style="width: 20px" aria-label="No">#</th>');
  $('#dataList thead tr').find('th').eq(-1).after('<th class="sorting_disabled" width="200px">Detail</th>');

});
</script>
